/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.theme.passport.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.UserDao;
import com.theme.passport.entity.UserEntity;
import com.theme.passport.entity.constant.UserReviewStatusEnum;
import com.theme.passport.service.ThirdUserService;
import com.theme.passport.service.UserReviewService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service("userReviewService")
public class UserReviewServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserReviewService {

    @Autowired
    private ThirdUserService thirdUserService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String reviewStatus = (String) params.get("reviewStatus");
        String keyword = (String) params.get("key");
        if (StringUtils.isNotBlank(reviewStatus)) {
            IPage<UserEntity> page = this.page(
                    new Query<UserEntity>().getPage(params),
                    new QueryWrapper<UserEntity>()
                            .like(StringUtils.isNotBlank(keyword), "nickname", keyword)
                            .eq(StringUtils.isNotBlank(reviewStatus), "review_status", reviewStatus)
            );
            return new PageUtils(page);
        }
        List<Integer> reviewStatusList = new ArrayList<>();
        reviewStatusList.add(UserReviewStatusEnum.AUDIT_TO_WAIT.getValue());
        reviewStatusList.add(UserReviewStatusEnum.AUDIT_NOT_PASS.getValue());
        IPage<UserEntity> page = this.page(
                new Query<UserEntity>().getPage(params),
                new QueryWrapper<UserEntity>()
                        .like(StringUtils.isNotBlank(keyword), "username", keyword)
                        .in("review_status", reviewStatusList)
        );
        return new PageUtils(page);
    }

}
